package com.itheima.test;

import net.sf.jasperreports.engine.JREmptyDataSource;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wmh
 * @version 1.0 2022/6/6
 * @Description: JasperReport模板导出
 **/
public class PdfDemo {
    public static void main(String[] args) throws Exception {
        String filePath = "d:\\test.jasper";
        FileInputStream inputStream = new FileInputStream(filePath);
        Map<String,Object> params = new HashMap<>();
        //字体处理
        params.put("userNameP","张三");
        params.put("phoneP","123456789854");
        //模板和数据的结合
        JasperPrint jasperPrint = JasperFillManager.fillReport(inputStream, params, new JREmptyDataSource());
        //
        JasperExportManager.exportReportToPdfStream(jasperPrint,new FileOutputStream("d:\\test01.pdf"));

    }
}